package com.example.wanxian.booktest;

import android.content.Intent;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.SaveListener;

public class AddActivity extends AppCompatActivity {
    private EditText addTitle;
    private Button addSave;
    private EditText addData;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add);
        initAddFloatButton();
        initAddTata();
    }
    private void initAddTata() {
        addTitle = findViewById(R.id.add_title);
        addData = findViewById(R.id.add_data);
        addSave = findViewById(R.id.add_save);
        addSave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String title = addTitle.getText().toString();
                String data = addData.getText().toString();
                notebook note = new notebook();
                note.setTitle(title);
                note.setContent(data);
                note.save(new SaveListener<String>() {
                    @Override
                    public void done(String s, BmobException e) {
                        if(e==null){
                            Toast.makeText(AddActivity.this,"保存成功",Toast.LENGTH_SHORT).show();
                            Intent intent = new Intent(AddActivity.this,MainActivity.class);
                            startActivity(intent);
                        }else{
                            Log.e("AddActivity","保存失败");
                        }
                    }
                });
            }
        });
    }

    private void initAddFloatButton() {
        FloatingActionButton delete = (FloatingActionButton)findViewById(R.id.add_delete);
        delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(AddActivity.this,"删除成功",Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(AddActivity.this,MainActivity.class);
                startActivity(intent);
            }
        });
        FloatingActionButton videoPath = (FloatingActionButton)findViewById(R.id.add_videoPath);
        videoPath.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(AddActivity.this,"视频",Toast.LENGTH_SHORT).show();
            }
        });
        FloatingActionButton location = (FloatingActionButton)findViewById(R.id.add_location);
        location.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(AddActivity.this,"定位",Toast.LENGTH_SHORT).show();
            }
        });
        FloatingActionButton audio = (FloatingActionButton)findViewById(R.id.add_audio);
        audio.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(AddActivity.this,"音频",Toast.LENGTH_SHORT).show();
            }
        });
        FloatingActionButton image = (FloatingActionButton)findViewById(R.id.add_image);
        image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(AddActivity.this,"图片",Toast.LENGTH_SHORT).show();
            }
        });
        FloatingActionButton append = (FloatingActionButton)findViewById(R.id.add_append);
        append.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(AddActivity.this,"附件",Toast.LENGTH_SHORT).show();
            }
        });
    }
}

